Repository navigation
fix(xbrl): de-duplicate enumeration facts without their whitespace (#1760) - #2039
Merged
Merged
Conversation
…1760) An extensible-enumeration value is an xs:token list of members, so the whitespace between members is not significant (Extensible Enumerations 2.0 section 6.2.2) and duplicate detection compares the collapsed value (section 6.2.3). `_deduplicate_facts` compared the raw `value`, so one member set filed once with a space and once with a line break stayed as two rows. FactsView.get_facts() now sets a hidden `dedup_value` (the collapsed value) on enumeration-typed facts only, matched on the local type name whatever prefix the schema binds to enum2. De-duplication compares it in place of `value`; it is listed in _DEDUP_OPTIONAL so the early projection keeps it, and in _SKIP_COLUMNS so it is not a frame column. `value` is never rewritten: the kept row is the first occurrence as filed, which keeps the "raw values as reported" contract and follows the issue's proposal. Plain strings keep comparing with their whitespace, since xs:string preserves it. The structured member comparison #1760 asked for across paths already exists as XBRL.enumeration_members() (#1255). Cracker Barrel's 10-K (0001104659-26-110772) keeps its three periods, each naming IL, KY, TN and TX, with the filed line breaks. Row counts of all 47 bundled XBRL fixtures (94,996 facts) are identical before and after. Fixes #1760 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
An extensible-enumeration value is an
xs:tokenlist of members. Whitespace between members isn't significant (Extensible Enumerations 2.0 §6.2.2), and duplicate detection compares the collapsed value (§6.2.3). The facts frame compared the rawvalue, so one member set filed once with a space and once with a line break stayed as two rows.How it works now:
FactsView.get_facts()sets a hiddendedup_value, the whitespace-collapsed value, on enumeration-typed facts only.value._DEDUP_OPTIONAL, so the narrowedquery().to_dataframe(*columns)path keeps it long enough._SKIP_COLUMNS, so it isn't a default frame column.valueis never rewritten. The kept row is the first occurrence exactly as filed, which preserves the "raw values as reported" contract in the API guide and follows the approach the issue proposed. Plain strings still compare with their whitespace, becausexs:stringpreserves it. For comparing members across the XBRL and inline paths,XBRL.enumeration_members(value)from #1255 already splits on any whitespace.Fixes #1760
Verification
Ground truth: the Cracker Barrel 10-K the issue cites (accession 0001104659-26-110772) still has three facts for three fiscal years ending 2024-08-02, 2025-08-01 and 2026-07-31. Each names IL, KY, TN and TX, and each value keeps its filed line breaks. This is the network test
test_cracker_barrel_state_sets_keep_their_three_periods.Regression test:
tests/issues/regression/test_issue_1760.pyhas 5 offline tests:xs:stringwith different whitespace stays as two rows;dedup_valueis not a default column.The two duplicate tests fail on main's
facts.py.No real data changes: row counts for all 47 bundled XBRL fixture filings (94,996 facts) are identical on main and with this change. 48,590 fast XBRL and regression tests pass.
Changelog:
changelog.d/1760.fixed.mdAI assistance
🤖 Generated with Claude Code